package de.bib.dashboard.swing.chart;

import java.awt.*;
import javax.swing.*;
import org.jfree.ui.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.general.*;
import org.jfree.chart.entity.*;

public class PieChart extends ApplicationFrame implements ChartMouseListener {

	private JFreeChart chart;
	private PiePlot plot;
	private int angle = 270;
	private static double explodePercent = 0.99;
	private static long count = 0;

	public PieChart(String title) {
		super(title);
		this.chart = ChartFactory.createPieChart("Pie Chart Demo",
				createDataset(), true, true, false);
		this.plot = (PiePlot) chart.getPlot();
		this.plot.setSectionOutlinesVisible(false);
		this.plot.setNoDataMessage("No data available");
		this.plot.setBackgroundAlpha(0.2f);
		this.plot.setBackgroundPaint(Color.WHITE);
		this.angle = 270;
		ChartPanel chartpanel = new ChartPanel(chart, false, false, false,
				false, false);
		chartpanel.setVisible(true);
		chartpanel.addChartMouseListener(this);
		chartpanel.setPreferredSize(new Dimension(500, 270));
		setContentPane(chartpanel);
	}

	private static PieDataset createDataset() {
		DefaultPieDataset dataset = new DefaultPieDataset();
		dataset.setValue("One", new Double(10.0));
		dataset.setValue("Two", new Double(20.0));
		dataset.setValue("Three", new Double(30.0));
		dataset.setValue("Four", new Double(40.0));
		dataset.setValue("Five", new Double(10.0));
		return dataset;
	}

	private static JFreeChart createChart(PieDataset dataset) {

		JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart Demo",
				dataset, true, true, false);

		PiePlot plot = (PiePlot) chart.getPlot();
		plot.setSectionOutlinesVisible(false);
		plot.setNoDataMessage("No data available");
		plot.setBackgroundAlpha(0.2f);
		return chart;
	}

	public static JPanel createDemoPanel() {
		JFreeChart chart = createChart(createDataset());
		ChartPanel chartpanel = new ChartPanel(chart, false, false, false,
				false, false);
		chartpanel.setVisible(true);
		chartpanel.setPreferredSize(new Dimension(500, 270));
		return new JPanel();
	}

	public static void main(String[] args) {
		PieChart demo = new PieChart("Pie Chart");
		demo.pack();
		RefineryUtilities.centerFrameOnScreen(demo);
		demo.setVisible(true);
	}

	public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
		ChartEntity chartentity = chartmouseevent.getEntity();
		if (chartentity != null) {
			System.out.println("Mouse clicked: " + chartentity.toString());
		} else
			System.out.println("Mouse clicked: null entity.");
	}

	public void chartMouseMoved(ChartMouseEvent chartmouseevent) {
	}
}